﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.InterferenceVolume.CApIVUtilities
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System.Collections.Generic;
using System.Collections.ObjectModel;
using Tecnomatix.Engineering;


namespace DnProcessSimulateCommands.InterferenceVolume;

public class CApIVUtilities
{
  public const double IV_TRANSPARENCY_LEVEL = 1.0;

  internal static ITxSweptVolumeHoldingObject GetSweptVolumeHoldingObject(TxSweptVolume sweptVolume)
  {
    ITxSweptVolumeHoldingObject volumeHoldingObject = (ITxSweptVolumeHoldingObject) null;
    if (TxSweptVolume.op_Inequality(sweptVolume, (ITxObject) null))
      volumeHoldingObject = sweptVolume.HoldingObject as ITxSweptVolumeHoldingObject;
    return volumeHoldingObject;
  }

  internal static bool IsEmptySweptVolume(TxSweptVolume sweptVolume)
  {
    bool flag = false;
    if (TxSweptVolume.op_Inequality(sweptVolume, (ITxObject) null))
      flag = sweptVolume.Visibility == 3;
    return flag;
  }

  internal static TxInterferenceVolume GetExistingInterferenceVolume(TxObjectList sweptVolumes)
  {
    TxInterferenceVolume interferenceVolume1 = (TxInterferenceVolume) null;
    if (sweptVolumes != null && ((Collection<ITxObject>) sweptVolumes).Count == 2 && ((Collection<ITxObject>) sweptVolumes)[0] != ((Collection<ITxObject>) sweptVolumes)[1])
    {
      bool flag1 = false;
      List<ITxInterferenceVolumeHoldingObject> volumeHoldingObjectList = new List<ITxInterferenceVolumeHoldingObject>(2);
      foreach (TxSweptVolume sweptVolume in (Collection<ITxObject>) sweptVolumes)
      {
        if (CApIVUtilities.GetSweptVolumeHoldingObject(sweptVolume) is ITxInterferenceVolumeHoldingObject volumeHoldingObject && !volumeHoldingObjectList.Contains(volumeHoldingObject))
        {
          volumeHoldingObjectList.Add(volumeHoldingObject);
        }
        else
        {
          flag1 = true;
          break;
        }
      }
      if (!flag1 && volumeHoldingObjectList.Count == ((Collection<ITxObject>) sweptVolumes).Count)
      {
        List<TxInterferenceVolume> interferenceVolumes = CApIVUtilities.GetInterferenceVolumes(volumeHoldingObjectList[0]);
        if (interferenceVolumes != null)
        {
          int count = volumeHoldingObjectList.Count;
          volumeHoldingObjectList.RemoveAt(0);
          foreach (TxInterferenceVolume interferenceVolume2 in interferenceVolumes)
          {
            List<ITxInterferenceVolumeHoldingObject> volumeHoldingObjects = CApIVUtilities.GetInterferenceVolumeHoldingObjects(interferenceVolume2);
            if (volumeHoldingObjects != null && volumeHoldingObjects.Count == count)
            {
              bool flag2 = true;
              foreach (ITxInterferenceVolumeHoldingObject volumeHoldingObject in volumeHoldingObjectList)
              {
                if (!volumeHoldingObjects.Contains(volumeHoldingObject))
                {
                  flag2 = false;
                  break;
                }
              }
              if (flag2)
              {
                interferenceVolume1 = interferenceVolume2;
                break;
              }
            }
          }
        }
      }
    }
    return interferenceVolume1;
  }

  internal static List<TxInterferenceVolume> GetInterferenceVolumes(
    ITxInterferenceVolumeHoldingObject holdingObject)
  {
    List<TxInterferenceVolume> interferenceVolumes1 = (List<TxInterferenceVolume>) null;
    if (holdingObject != null)
    {
      TxObjectList interferenceVolumes2 = holdingObject.InterferenceVolumes;
      if (interferenceVolumes2 != null)
      {
        interferenceVolumes1 = new List<TxInterferenceVolume>(((Collection<ITxObject>) interferenceVolumes2).Count);
        foreach (TxInterferenceVolume interferenceVolume in (Collection<ITxObject>) interferenceVolumes2)
          interferenceVolumes1.Add(interferenceVolume);
      }
    }
    return interferenceVolumes1;
  }

  internal static List<ITxInterferenceVolumeHoldingObject> GetInterferenceVolumeHoldingObjects(
    TxInterferenceVolume interferenceVolume)
  {
    List<ITxInterferenceVolumeHoldingObject> volumeHoldingObjects = (List<ITxInterferenceVolumeHoldingObject>) null;
    if (TxInterferenceVolume.op_Inequality(interferenceVolume, (ITxObject) null))
    {
      TxObjectList holdingObjects = interferenceVolume.HoldingObjects;
      if (holdingObjects != null)
      {
        volumeHoldingObjects = new List<ITxInterferenceVolumeHoldingObject>(((Collection<ITxObject>) holdingObjects).Count);
        foreach (ITxInterferenceVolumeHoldingObject volumeHoldingObject in (Collection<ITxObject>) holdingObjects)
          volumeHoldingObjects.Add(volumeHoldingObject);
      }
    }
    return volumeHoldingObjects;
  }

  internal static bool IsOperation(ITxObject obj)
  {
    bool flag = false;
    if (obj != null && obj is ITxOperation)
      flag = true;
    return flag;
  }

  internal static bool IsRoboticProgram(ITxObject obj)
  {
    bool flag = false;
    if (obj != null && obj is TxRoboticProgram)
      flag = true;
    return flag;
  }

  internal static TxColor GetColor(ITxDisplayableObject obj)
  {
    TxColor color = (TxColor) null;
    if (obj != null)
    {
      try
      {
        color = obj.Color;
      }
      catch
      {
      }
    }
    return color;
  }

  internal static bool SetColor(ITxDisplayableObject obj, TxColor color)
  {
    bool flag = false;
    if (obj != null)
    {
      if (TxColor.op_Inequality(color, (TxColor) null))
      {
        try
        {
          obj.Color = color;
          flag = true;
        }
        catch
        {
        }
      }
    }
    return flag;
  }

  internal static bool DisplayObject(ITxDisplayableObject displayableObj)
  {
    bool flag = false;
    if (displayableObj != null)
    {
      try
      {
        displayableObj.Display();
        flag = true;
      }
      catch
      {
        flag = false;
      }
    }
    return flag;
  }
}
